<template>
	<div id="app">
		<router-view></router-view>
	</div>
</template>

<script>
	export default {
		name: 'App',
		created(){
      if(location.host != "hk.xinxinming.top"){
        axios.get('/agent/customer/service/token').then((response)=>{
        	if (response.data.msg.code == 0) {
        		// var user_id = response.data.data.id
        		if(response.data.data.customer_service_open){
        		var isShowTip = true
        		}else{
        		var isShowTip = false
        		}

        		var usetoken = response.data.data.customer_service_token
        		var usekefuid = response.data.data.yun_cust_id


					var currentDomain = window.location.hostname;

					var protocol = window.location.protocol;
					console.log(protocol);

					var _s = document.createElement('script');

					if(currentDomain == 'localhost'){
						_s.src="../static/img/customerServer.js"
						var openUrl = 'http://kf.xiaoluohao.vip'
					}else if (protocol === "http:") {
						console.log("当前是http");
						_s.src="../web/static/img/customerServer.js"
						var openUrl = 'http://kf.xiaoluohao.vip'
					} else if (protocol === "https:") {
						console.log("当前是https");
						_s.src="../web/static/img/customerServer.js"
						var openUrl = 'https://kf.xiaoluohao.vip'
					}






					_s.onload = function(){
					var option = {
						"authInit":true,
						openUrl: openUrl,
						token: usetoken,
						kefuid:usekefuid,//默认为空自动对接客服，可填写指定客服ID
						isShowTip: isShowTip, // 初始化成功后，界面右下角会自动创建 “联系客服按钮”， 如无需默认展示，则填写false即可,默认为true
						mobileIcon: '', //  手机端悬浮客服图片
						pcIcon: '', // pc端悬浮客服图片
						windowStyle:'center',//默认空 右下角小弹窗， center 普通中间弹窗样式
						 sendUserData: {
								nickName: JSON.parse(localStorage.getItem('user')).name, // 用户昵称
							}
						};

						console.log(option)
						var canCustomerServer = new initCustomerServer(option);

        			canCustomerServer.init();
        		}
        		// document.head.replaceChild(_s)
        		document.head.appendChild(_s)



        	} else {
        	// this.$message.error(response.data.msg.info);
        	}
        })
      }

		}
	}
</script>

<style lang="less">
	@import "~@/assets/all.less";
</style>
